using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace Adex
{
    /// <summary>
    /// Controller class for CommercialLog1
    /// </summary>
    [System.ComponentModel.DataObject]
    public partial class CommercialLog1Controller
    {
        // Preload our schema..
        CommercialLog1 thisSchemaLoad = new CommercialLog1();
        private string userName = String.Empty;
        protected string UserName
        {
            get
            {
				if (userName.Length == 0) 
				{
    				if (System.Web.HttpContext.Current != null)
    				{
						userName=System.Web.HttpContext.Current.User.Identity.Name;
					}
					else
					{
						userName=System.Threading.Thread.CurrentPrincipal.Identity.Name;
					}
				}
				return userName;
            }
        }
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public CommercialLog1Collection FetchAll()
        {
            CommercialLog1Collection coll = new CommercialLog1Collection();
            Query qry = new Query(CommercialLog1.Schema);
            coll.LoadAndCloseReader(qry.ExecuteReader());
            return coll;
        }
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public CommercialLog1Collection FetchByID(object Id)
        {
            CommercialLog1Collection coll = new CommercialLog1Collection().Where("ID", Id).Load();
            return coll;
        }
		
		[DataObjectMethod(DataObjectMethodType.Select, false)]
        public CommercialLog1Collection FetchByQuery(Query qry)
        {
            CommercialLog1Collection coll = new CommercialLog1Collection();
            coll.LoadAndCloseReader(qry.ExecuteReader()); 
            return coll;
        }
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public bool Delete(object Id)
        {
            return (CommercialLog1.Delete(Id) == 1);
        }
        [DataObjectMethod(DataObjectMethodType.Delete, false)]
        public bool Destroy(object Id)
        {
            return (CommercialLog1.Destroy(Id) == 1);
        }
        
        
    	
	    /// <summary>
	    /// Inserts a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Insert, true)]
	    public void Insert(string MediaCode,string RFDate,string TimeStart,string TimeEnd,string Duration,string ProgramCode,string ProgramName,string Typology,decimal? NominalCost,decimal? RealCost,string PositionInBreak,string NumberOfSpotsInBreak,string TypeOfSpot,string TypeOfBuyCode,string TypeOfBuyName,string ProdVersionCode,string ProdVersionName,string ProductCode,string ProductName,string Constant1,string Constant2,string CategoryCode,string CategoryName,string SubSectorCode,string SubSectorName,string SectorCode,string SectorName,string Constant3,string BrandCode,string BrandName,string AdvertiserCode,string AdvertiserName,string Constant4,string AgencyCode,string AgencyName,string CountryID,bool? FullVideo,bool? ShortVideo,string FullVideoFile,string ShortVideoFile,string RadioFile,string CableFile,bool? PreliminaryData)
	    {
		    CommercialLog1 item = new CommercialLog1();
		    
            item.MediaCode = MediaCode;
            
            item.RFDate = RFDate;
            
            item.TimeStart = TimeStart;
            
            item.TimeEnd = TimeEnd;
            
            item.Duration = Duration;
            
            item.ProgramCode = ProgramCode;
            
            item.ProgramName = ProgramName;
            
            item.Typology = Typology;
            
            item.NominalCost = NominalCost;
            
            item.RealCost = RealCost;
            
            item.PositionInBreak = PositionInBreak;
            
            item.NumberOfSpotsInBreak = NumberOfSpotsInBreak;
            
            item.TypeOfSpot = TypeOfSpot;
            
            item.TypeOfBuyCode = TypeOfBuyCode;
            
            item.TypeOfBuyName = TypeOfBuyName;
            
            item.ProdVersionCode = ProdVersionCode;
            
            item.ProdVersionName = ProdVersionName;
            
            item.ProductCode = ProductCode;
            
            item.ProductName = ProductName;
            
            item.Constant1 = Constant1;
            
            item.Constant2 = Constant2;
            
            item.CategoryCode = CategoryCode;
            
            item.CategoryName = CategoryName;
            
            item.SubSectorCode = SubSectorCode;
            
            item.SubSectorName = SubSectorName;
            
            item.SectorCode = SectorCode;
            
            item.SectorName = SectorName;
            
            item.Constant3 = Constant3;
            
            item.BrandCode = BrandCode;
            
            item.BrandName = BrandName;
            
            item.AdvertiserCode = AdvertiserCode;
            
            item.AdvertiserName = AdvertiserName;
            
            item.Constant4 = Constant4;
            
            item.AgencyCode = AgencyCode;
            
            item.AgencyName = AgencyName;
            
            item.CountryID = CountryID;
            
            item.FullVideo = FullVideo;
            
            item.ShortVideo = ShortVideo;
            
            item.FullVideoFile = FullVideoFile;
            
            item.ShortVideoFile = ShortVideoFile;
            
            item.RadioFile = RadioFile;
            
            item.CableFile = CableFile;
            
            item.PreliminaryData = PreliminaryData;
            
	    
		    item.Save(UserName);
	    }
    	
	    /// <summary>
	    /// Updates a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
	    public void Update(int Id,string MediaCode,string RFDate,string TimeStart,string TimeEnd,string Duration,string ProgramCode,string ProgramName,string Typology,decimal? NominalCost,decimal? RealCost,string PositionInBreak,string NumberOfSpotsInBreak,string TypeOfSpot,string TypeOfBuyCode,string TypeOfBuyName,string ProdVersionCode,string ProdVersionName,string ProductCode,string ProductName,string Constant1,string Constant2,string CategoryCode,string CategoryName,string SubSectorCode,string SubSectorName,string SectorCode,string SectorName,string Constant3,string BrandCode,string BrandName,string AdvertiserCode,string AdvertiserName,string Constant4,string AgencyCode,string AgencyName,string CountryID,bool? FullVideo,bool? ShortVideo,string FullVideoFile,string ShortVideoFile,string RadioFile,string CableFile,bool? PreliminaryData)
	    {
		    CommercialLog1 item = new CommercialLog1();
	        item.MarkOld();
	        item.IsLoaded = true;
		    
			item.Id = Id;
				
			item.MediaCode = MediaCode;
				
			item.RFDate = RFDate;
				
			item.TimeStart = TimeStart;
				
			item.TimeEnd = TimeEnd;
				
			item.Duration = Duration;
				
			item.ProgramCode = ProgramCode;
				
			item.ProgramName = ProgramName;
				
			item.Typology = Typology;
				
			item.NominalCost = NominalCost;
				
			item.RealCost = RealCost;
				
			item.PositionInBreak = PositionInBreak;
				
			item.NumberOfSpotsInBreak = NumberOfSpotsInBreak;
				
			item.TypeOfSpot = TypeOfSpot;
				
			item.TypeOfBuyCode = TypeOfBuyCode;
				
			item.TypeOfBuyName = TypeOfBuyName;
				
			item.ProdVersionCode = ProdVersionCode;
				
			item.ProdVersionName = ProdVersionName;
				
			item.ProductCode = ProductCode;
				
			item.ProductName = ProductName;
				
			item.Constant1 = Constant1;
				
			item.Constant2 = Constant2;
				
			item.CategoryCode = CategoryCode;
				
			item.CategoryName = CategoryName;
				
			item.SubSectorCode = SubSectorCode;
				
			item.SubSectorName = SubSectorName;
				
			item.SectorCode = SectorCode;
				
			item.SectorName = SectorName;
				
			item.Constant3 = Constant3;
				
			item.BrandCode = BrandCode;
				
			item.BrandName = BrandName;
				
			item.AdvertiserCode = AdvertiserCode;
				
			item.AdvertiserName = AdvertiserName;
				
			item.Constant4 = Constant4;
				
			item.AgencyCode = AgencyCode;
				
			item.AgencyName = AgencyName;
				
			item.CountryID = CountryID;
				
			item.FullVideo = FullVideo;
				
			item.ShortVideo = ShortVideo;
				
			item.FullVideoFile = FullVideoFile;
				
			item.ShortVideoFile = ShortVideoFile;
				
			item.RadioFile = RadioFile;
				
			item.CableFile = CableFile;
				
			item.PreliminaryData = PreliminaryData;
				
	        item.Save(UserName);
	    }
    }
}
